<template>
  <div class="Qcgl">
    <!-- 第一行 -->
    <el-row>
      <el-col>
        <div class="header_title">器材管理</div>
      </el-col>
    </el-row>
    <!-- 第二行 -->
    <el-row>
      <el-col>
        <div class="content_search">
          <el-form ref="form" :model="searchData" label-width="80px">
            <el-form-item label="器材分类" size="small">
              <el-select
                v-model="searchData.equipment_type"
                placeholder="请选择器材"
                clearable
              >
                <el-option
                  v-for="(v, i) in equipment_typeData"
                  :key="i"
                  :label="v.name"
                  :value="v.id"
                ></el-option>
              </el-select>
            </el-form-item>
            <el-form-item label="存放区域" size="small">
              <el-select
                v-model="searchData.storage_area"
                placeholder="请选择部门"
                clearable
              >
                <el-option
                  v-for="(v, i) in storage_areaData"
                  :key="i"
                  :label="v.name"
                  :value="v.id"
                ></el-option>
              </el-select>
            </el-form-item>
            <el-form-item label="搜索">
              <el-input
                v-model="searchData.search_Info"
                placeholder="请输入器材编号或名称"
                size="small"
              ></el-input>
            </el-form-item>
            <!-- 按钮组 -->
            <div class="btn_type">
              
              <el-button
                type="primary"
                icon="el-icon-zoom-in"
                @click="onSearch"
                size="mediu"
                >查询</el-button
              >

              <el-button
                type="success"
                icon="el-icon-plus"
                @click="onAddInfo"
                size="mediu"
                >新增</el-button
              >
              
              <el-button
                type="info"
                icon="el-icon-refresh-right"
                @click="onReset"
                >重置</el-button
              >
            </div>
          </el-form>
        </div>
      </el-col>
    </el-row>
    <!-- 表格数据 -->
    <el-table
      ref="multipleTable"
      :data="QqglData"
      tooltip-effect="dark"
      style="width: 100%"
      @selection-change="handleSelectionChange"
    >
      <el-table-column
        type="selection"
        width="60"
        align="center"
      ></el-table-column>
      <el-table-column prop="number" label="器材编号" align="center">
        <!-- <template slot-scope="scope">{{ scope.row.date }}</template> -->
      </el-table-column>
      <el-table-column prop="name" label="器材名称" align="center">
      </el-table-column>
      <el-table-column
        prop="wfacilityClass2.name"
        label="器材分类"
        align="center"
      ></el-table-column>
      <el-table-column
        prop="model"
        label="规格型号"
        align="center"
      ></el-table-column>
      <el-table-column prop="facilityUnit.unit" label="单位" align="center">
      </el-table-column>
      <el-table-column
        prop="location.region.name"
        label="存放区域"
        align="center"
      ></el-table-column>
      <el-table-column
        prop="location.name"
        label="货拉"
        align="center"
      ></el-table-column>
      <el-table-column width="200" label="操作" align="center">
        <template slot-scope="scope">
          <el-button
            class="edit_btn"
            type="primary"
            icon="el-icon-edit-outline"
            @click="openEdit(scope.row)"
          >
          </el-button>
          <el-button
            class="del_btn"
            type="primary"
            icon="el-icon-delete"
            @click="delInfo(scope.row.number)"
          >
          </el-button>
        </template>
      </el-table-column>
    </el-table>
    <!-- 页码 -->
    <el-col :span="24">
      <div class="grid_content">
        <el-button
          class="del_btn"
          type="primary"
          icon="el-icon-delete"
          @click="delAllInfo"
          size="small"
        >
          删除
        </el-button>
        <el-button size="small" type="info" plain @click="cancelSelection(QqglData)">反选</el-button>
        <el-button size="small" type="primary" plain @click="cancelSelection()">取消</el-button>
        <span class="page_total"
          >共{{ Math.ceil(total / qcgl_limit) }}页/{{ total }}条数据</span
        >
        <el-pagination
          @current-change="qcgl_changePage"
          layout="prev, pager, next, jumper"
          :current-change.sync="qcgl_page"
          :total="total"
          :page-size="qcgl_limit"
        >
        </el-pagination>
        <span class="go_page">跳转</span>
      </div>
    </el-col>
  </div>
</template>

<script>
export default {
  data: function () {
    return {
      search_input: "",
      searchData: {
        search_Info: "",
        equipment_type: "",
        storage_area: "",
      },
      QqglData: [
        {
          code: "111",
          name: "测试名称",
          type: "测试分类",
          model: "测试型号",
          company: "测试单位",
          saveArea: "测试存放区域",
          goodsId: "测试货拉Id",
        },
        {
          code: "222",
          name: "测试名称2",
          type: "测试分类2",
          model: "测试型号2",
          company: "测试单位2",
          saveArea: "测试存放区域2",
          goodsId: "测试货拉Id2",
        },
      ],
      // 器材类型
      storage_areaData: [],
      // 部门类型
      equipment_typeData: [],
      qcgl_page: 1,
      qcgl_limit: 5,
      total: 0,
      // 多选复选项数据
      multipleDelSelectionData: [],
    };
  },
  methods: {
    //获取数据
    getQqglData: function () {
      this.$axios({
        url: "/wFacilityManagement/list",
        method: "post",
        data: {
          wfacilityClass2Id: this.searchData.equipment_type,
          wregionId: this.searchData.storage_area,
          wequipManagemhb: this.searchData.search_Info,
          page: this.qcgl_page,
          limit: this.qcgl_limit,
        },
      }).then((res) => {
        // console.log("器材管理data",res)
        if (res.data.code == 0) {
          this.QqglData = res.data.data;
          this.total = res.data.total;
          // this.$message.success("数据加载成功！");
        } else {
          this.$message.error("数据加载失败！");
        }
      });
    },
    // 重置
    onReset: function () {
      this.searchData.equipment_type = "";
      this.searchData.storage_area = "";
      this.searchData.search_Info = "";
      this.qcgl_page = 1;
      this.getQqglData();
    },
    // 搜索
    onSearch: function () {
      this.getQqglData();
    },
    // 添加信息
    onAddInfo: function () {
      // this.$message.success("添加信息");
      this.$router.push("/Qcgl/Qcgl_xz");
    },
    // 修改
    openEdit: function (row) {
      let qcgl_data = row;
      this.$store.state.tjy_vuex.qcgl_edit = qcgl_data
      sessionStorage.setItem("qcglInfo", JSON.stringify(qcgl_data));
      this.$router.push("/Qcgl/Qcgl_xg");
    },
    // 单条记录删除
    delInfo: function (numberId) {
      let id = numberId
      // console.log(id)
      this.$confirm("此操作将永久删除该文件, 是否继续?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          this.$axios({
            url: "/wEquipManage/delete",
            method: "post",
            data: [id],
          }).then((res) => {
            // console.log(res);
            // console.log(id);
            if (res.data.code == 0) {
              this.$message({
                type: "success",
                message: "删除成功!",
              });
              this.getQqglData();
            } else {
              this.$message({
                type: "info",
                message: "删除失败！！！",
              });
            }
          });
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "取消删除",
          });
        });
    },

    // 多条记录删除(未写完)
    delAllInfo: function () {
      // 空值提示
      if (this.multipleDelSelectionData == "") {
        this.$message({
          title: "温馨提示：",
          message: "您未选中需要删除的数据，请重新操作！！！",
          type: "warning",
        });
        return;
      }
      let DelSelectionData = this.multipleDelSelectionData;
      let delData = [];
      DelSelectionData.forEach((v) => {
        // delData.push(v.number);
        delData.push(v.number);
        // delData.push([v.number]);
        this.$confirm("此操作将永久删除该文件, 是否继续?", "提示", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning",
        })
          .then(() => {
            this.$axios({
              url: "/wEquipManage/delete",
              method: "post",
              data:delData
            }).then((res) => {
              // console.log(res);
              // console.log(number);
              if (res.data.code == 0) {
                this.$message({
                  type: "success",
                  message: "删除成功!",
                });
                this.qcgl_page = 1
                this.getQqglData();
              } else {
                this.$message({
                  type: "info",
                  message: "删除失败！！！",
                });
              }
            });
          })
          .catch(() => {
            this.$message({
              type: "info",
              message: "取消删除",
            });
          });
      });
      // console.log("多条记录删除", delData);
    },

    // 取消多条选择的记录
    cancelSelection: function (rows) {
      // console.log("取消全选", rows);
      if (rows) {
        rows.forEach((row) => {
          // console.log(row);
          this.$refs.multipleTable.toggleRowSelection(row);
        });
      } else {
        this.$refs.multipleTable.clearSelection();
      }
    },
    // 选择的数据添加到一个数组
    handleSelectionChange(rowData) {
      // console.log(rowData);
      this.multipleDelSelectionData = rowData;
    },
    // 页码
    qcgl_changePage: function (page) {
      // console.log(page)
      this.qcgl_page = page;
      this.getQqglData();
    },
    // 器材分类下拉
    equipment_type: function () {
      this.$axios({
        url: "/wFacilityClass2/list",
        method: "get",
      }).then((res) => {
        if (res.data.code == 0) {
          this.equipment_typeData = res.data.data;
        } else {
          this.$message.error("器材分类下拉框数据加载失败！");
        }
      });
    },

    // 存放区域列表
    storage_area: function () {
      this.$axios({
        url: "/wRegion/list",
        method: "get",
      }).then((res) => {
        // console.log(res)
        if (res.data.code == 0) {
          this.storage_areaData = res.data.data;
        } else {
          this.$message.error("存放区域下拉框数据加载失败！");
        }
      });
    },
  },
  //
  mounted: function () {
    this.getQqglData();
    // 存放区域下拉
    this.storage_area();
    // 器材分类
    this.equipment_type();
  },
};
</script>


<style lang="less" scoped>
.Qcgl {
  padding: 30px;
  .header_title {
    font-weight: 700;
    font-style: normal;
    font-size: 24px;
    color: #344563;
    margin-bottom: 20px;
  }

  .content_search {
    height: 60px;
    width: 100%;
    background: #ffffff;
    // background: yellow;
    font-size: 16px;
    line-height: 60px;
    color: #344563;
    font-weight: bolder;
    .el-form {
      height: 50px;
      line-height: 50px;
      min-width: 1450px;
    }
    .el-form-item {
      width: 300px;
      height: 40px;
      display: inline-block;
    }
    // 输入框
    .el-input {
      width: 200px;
    }

    .btn_type {
      width: 340px;
      height: 41px;
      line-height: 41px;
      display: inline-block;
    }

    .el-button {
      padding: 0;
      text-align: center;
      width: 80px;
      height: 40px;
      line-height: 40px;
      margin-left: 30px;
    }
    .el-icon-search {
      font-size: 28px;
    }

    .el-icon-refresh-right {
      font-size: 28px;
    }
    .reset_btn {
      border-color: #61a4e4;
      background: #61a4e4;
    }
    .add_btn {
      border-color: #67c23a;
      background: #67c23a;
    }
  }

  .del_btn {
    font-size: 14px;
    color: #ffc5c5;
    background: #fef3f3;
    border-color: #fef3f3;
  }

  .edit_btn {
    font-size: 14px;
    color: #5fa4e2;
    font-weight: bolder;
    background: #eef6fc;
    border-color: #eef6fc;
  }
  .el-table {
    margin-top: 20px;
    padding: 20px 25px 0px 10px;
    // border-top: 1px solid #aaa;
    // border-bottom: 1px solid #aaa;
  }
  // 底部页码
  .grid_content {
    // background: #61a4e4;
    margin-top: 20px;
    line-height: 40px;
    position: relative;
  }
  .el-pagination {
    border-radius: 10px;
    position: absolute;
    top: 5px;
    right: 90px;
    color: #a1a1a1;
  }
  .go_page {
    font-size: 14px;
    position: absolute;
    top: 0;
    right: 50px;
    color: #7161c5;
    &:hover {
      cursor: pointer;
    }
  }
  .page_total {
    font-size: 14px;
    position: absolute;
    top: 0;
    right: 620px;
    color: #a8afbc;
  }
}
</style>